
// isEmail: void -> boolean
// Returns true if the email address is valid, otherwise it returns false.
function isEmail(){
	// regular expression for e-mail
	// http://www.marketingtechblog.com/javascript-regex-emailaddress/
	var pattern= /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})$/i;
	return pattern.test($("iEmail").value);
}

// emailsMatch: void -> boolean
// returns true if the e-mail and validate e-mail fields match
// otherwise, returns false
function emailsMatch(){
	return $("iEmail").value==$("ivEmail").value;
}

// checkEmails: void -> HTML
// if the the e-mail does not match the verify e-mail, then the vemail paragraph tag is filled with
//     "E-mails do not match"
// otherwise, makes the vemail paragraph tag empty
function checkEmails(){
	// The e-mails do not match
	if(!emailsMatch()){
		$("vemail").innerHTML="E-mails do not match.";
	} else {
		$("vemail").innerHTML="";
	}
}

// validateEmail: void -> HTML
// if the e-mail is invalid, it adds "Not a valid e-mail" to the "email" paragraph
// otherwise, it will clear the "Not a valid e-mail" if that text is present
function validateEmail(){
	// not a valid e-mail
	if(!isEmail()){
		$("email").innerHTML="Not a valid e-mail.";
	} else{
		$("email").innerHTML="";
	}
}

// userExists: string -> boolean
// returns true if the user already exists
// otherwise, returns false
function userExists(){
	
}

window.onload=function(){
	//$("create").disable();
	$("iEmail").onchange=validateEmail;
	$("ivEmail").onchange=checkEmails;
};